import { Client } from "./mod.ts";

/**
 * Repository File API endpoints
 */
export class FileAPI {
  constructor(private client: Client) {}

  /**
   * Get a file from a repository
   * @param owner - Owner of the repository
   * @param repo - Name of the repository
   * @param ref - Branch/tag/commit name
   * @param path - Path to the file (without leading slash)
   * @returns File content as Uint8Array
   */
  async getFile(owner: string, repo: string, ref: string, path: string): Promise<Uint8Array> {
    return await this.client.doRequest<Uint8Array>(
      "GET", 
      `/repos/${owner}/${repo}/raw/${ref}/${path}`,
      {},
      undefined,
      "arraybuffer"
    );
  }

  /**
   * Get the full contents of a repository as an archive
   * @param owner - Owner of the repository
   * @param repo - Name of the repository
   * @param ref - Branch/tag/commit name
   * @param format - Archive format (.zip or .tar.gz)
   * @returns Archive as Uint8Array
   */
  async getArchive(owner: string, repo: string, ref: string, format: ".zip" | ".tar.gz"): Promise<Uint8Array> {
    return await this.client.doRequest<Uint8Array>(
      "GET", 
      `/repos/${owner}/${repo}/archive/${ref}${format}`,
      {},
      undefined,
      "arraybuffer"
    );
  }
} 